package MineGod;

import java.util.ArrayList;

public class EmitterFire extends Emitter {
        
        public double width;
        public boolean off = true;

        public EmitterFire(){
                
                super(300.0, 300.0, .05, .01, -.01, -.03, -.02, 1550,1450);
                //super(x, y, r, sxmax, sxmin, symax, symin, lmax, lmin);
                width = 7.0;
        }

        public void step(int delta){
                //Set position of the emitter to player.
                setPosition(MineGod.player.getScreenX() + 6, MineGod.player.yPos);
                
                //Spawn new particles:
                if (!(off)){
                	for(int i = 0; i < spawnRate*delta; i++){
                		double pxSpeed = particleXspeedMin + Chunk.rand.nextDouble()*(particleXspeedMax-particleXspeedMin);
                        double pySpeed = particleYspeedMin + Chunk.rand.nextDouble()*(particleYspeedMax-particleYspeedMin);
                        double life = particleLifeMin + Chunk.rand.nextInt((int) particleLifeMax - (int) particleLifeMin);
                        double x = xPos - (width/2) + Chunk.rand.nextDouble()*(xPos+width - xPos);
                        particles.add(new FireParticle(life,x, yPos, pxSpeed, pySpeed));
                
                	}
                }
                
                //Update particles:
                ArrayList<Particle> delList = new ArrayList<Particle>();
                for (Particle p : particles){
                        p.update(delta);
                        if (p.life <= 0){
                                delList.add(p);
                        }
                }
                //delete dead particles:
                for (Particle p : delList){
                        particles.remove(p);
                }
                if (particles.isEmpty()){
                	this.alive = false;
                }
                
        }
        
}
